'''
  一批产品共N个，其中废品有M个。现在从中随机（或者随意）取出n个，问“其中恰好m个废品”这个事件E的概率是多少？

答案：
 P(E) = (M m)(N-M n-m)/(N n)
'''
import numpy as np

from scipy.special import comb

# 前提条件
N = 10000
M = 10
n = 80
m = 1
# 试验次数
cycle_count = 10000
# 等于3次的次数
count = 0
index = np.random.randint(0, M, size=m)
print(index)
for i in range(cycle_count):
    sum = 0
    for j in range(n):
        item = np.random.randint(0, M)
        if item in index:
            sum += 1
    if sum == m:
        count += 1

expect_result = comb(M, m) * comb(N - M, n - m) / comb(N, n)
print(f"actual:{count * 1.0 / cycle_count},expect:{expect_result}")
